package me.exchange.com.modules.system.domain;

import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;

import javax.persistence.*;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Objects;

/**
 * @author Zheng Jie
 * @date 2018-11-22
 */
@Entity
@Getter
@Setter
@Table(name="sys_user")
@org.hibernate.annotations.Table(appliesTo = "sys_user",comment="后台管理平台用户表")
public class User implements Serializable {

    /** serialVersionUID*/
	private static final long serialVersionUID = 1L;

	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @NotNull(groups = Update.class)
    @ApiModelProperty(name = "id",value = "ID")
    private Long id;

	/** 用户名*/
    @NotBlank
    @Column(unique = true,name = "username")
    @ApiModelProperty(name = "username",value = "用户名",required = false)
    private String username;

    /** 密码*/
    @Column(name = "password")
    @ApiModelProperty(name = "password",value = "密码",required = false)
    private String password;

    /** 部门名称*/
    @Column(name = "dept_id")
    @ApiModelProperty(name = "deptId",value = "部门名称")
    private Long deptId;
/*   @JoinColumn(name="dept_id")
   private Dept dept;*/

    /** 用户名称 */
    @NotBlank
    @Column(name="nick_name")
    @ApiModelProperty(name = "nickName",value = "用户名称",required = false)
    private String nickName;

    /** 性别 */
    @Column(name = "sex")
    @ApiModelProperty(name = "sex",value = "性别",required = false)
    private String sex;

    /** 邮箱*/
    @NotBlank
    @Email
    @Column(name = "email")
    @ApiModelProperty(name = "email",value = "邮箱",required = false)
    private String email;

    /** 手机号码*/
    @NotBlank
    @Column(name = "phone")
    @ApiModelProperty(name = "phone",value = "手机号码",required = false)
    private String phone;

    /** 角色ID*/
    @Column(name = "role_id")
    @ApiModelProperty(name = "roleId",value = "角色ID",required = false)
    private Long  roleId;
/*    @ManyToMany
    @JoinTable(name = "sys_users_roles", joinColumns = {@JoinColumn(name = "user_id",referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "role_id",referencedColumnName = "id")})
    private Set<Role> roles;*/

    /** 头像*/
    @Column(name = "avatar_path")
    @ApiModelProperty(name = "avatarPath",value = "头像",required = false)
    private String avatarPath;

    /** 状态 1启动 2禁用*/
    @NotNull
    @Column(name = "enabled")
    @ApiModelProperty(name = "enabled",value = "状态：1启用 0禁用")
    private Boolean enabled;

    /** 最后修改密码的日期*/
    @Column(name = "last_password_reset_time")
    @ApiModelProperty(name = "lastPasswordResetTime",value = "最后修改密码的日期",required = false)
    private Date lastPasswordResetTime;

    /** 创建人*/
    @Column(name = "c_admin_id")
    @ApiModelProperty(name = "cAdminId",value = "创建人",required = false)
    private Long cAdminId;

    /** 创建时间*/
    @Column(name = "c_admin_time")
    @CreationTimestamp
    @ApiModelProperty(name = "cAdminTime",value = "创建时间",required = false)
    private Timestamp cAdminTime;

    /** 修改人*/
    @Column(name = "u_admin_id")
    @ApiModelProperty(name = "uAdminId",value = "修改人",required = false)
    private Long uAdminId;

    /** 修改时间  */
    @Column(name = "u_admin_time")
    @CreationTimestamp
    @ApiModelProperty(name = "uAdminTime",value = "修改时间",required = false)
    private Timestamp uAdminTime;

    /** 谷歌秘钥*/
    @Column(name = "google_key")
    @ApiModelProperty(name = "googleKey",value = "谷歌秘钥",required = false)
    private String googleKey;

    /** 备注*/
    @Column(name = "remark")
    @ApiModelProperty(name = "remark",value = "备注",required = false)
    private String remark;

    /** 是否删除*/
    @Column(name = "isdel")
    @ApiModelProperty(name = "isdel",value = "是否删除",required = false)
    private Boolean isdel;

    public @interface Update {}

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        User user = (User) o;
        return Objects.equals(id, user.id) &&
                Objects.equals(username, user.username);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, username);
    }
}